<?php
namespace app\admin\controller;

/**
 * 商家
 * Class Member
 */
class ShopController extends BaseController {

    protected function _initialize() {
        parent::_initialize();
    }
	//自定义分类
	public function goods_type(){
		$list = db('goodstype')->select();
		$list=array2level($list);
		$this->assign('list',$list);
		return $this->fetch();
	}

	/**
     * 添加自定义分类
     */
    public function add_goodstype() {
		if($_POST){
			$data = get_query()['query'];
			$data['add_time'] = now_time();
			$res = add_data("goodstype",$data);
			if($res){
				 $this->success('添加成功',url("goods_type"));
			}else{
				 $this->success('添加失败');
			}
		}
		
		$list = db('goodstype')->select();
		$this->assign('list',$list);
		$this->assign('pid',input('pid'));
		return $this->fetch();
	}
	//编辑自定义分类
	public function edit_goodstype(){
		if($_POST){
			$res=update_data("goodstype",get_query()['query']);
			if($res){
				 $this->success('更新成功',url("goods_type"));
			}else{
				 $this->success('更新失败');
			}
		}
		$list=db("goodstype")->where("id",input("id"))->find();
		$this->assign('list',$list);
		
		$typelist = db('goodstype')->select();
		$typelist=array2level($typelist);
		$this->assign('typelist',$typelist);
		return $this->fetch();
	}
	
	//删除分类
	public function delete_item(){
		$res = del_data("goodstype",input("id"));
		if($res){
			 $this->success('删除成功',url("goods_type"));
		}else{
			 $this->success('删除失败');
		}
	}
}
